package kitrobot.com.bed.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

import kitrobot.com.bed.Service.DelepoService;
import kitrobot.com.bed.Service.PowerlistService;
import kitrobot.com.bed.Service.SelepoService;
import kitrobot.com.bed.Service.UpnextService;
import kitrobot.com.wechat_bottom_navigation.R;

public class UpdatepersonActivity extends AppCompatActivity implements View.OnClickListener {
    private String puphone;
    private String puname;
    private String puid;
    private String starttime;
    private String endtime;
    private String appuser_id;
    private String bid;
    private String token;
    private TextView et_upt;
    private TextView et_upn;
    private EditText et_usd;
    private EditText et_ued;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.update_person);
        Intent intent = getIntent();
        bid =  intent.getStringExtra("bid");
        puid =  intent.getStringExtra("puid");
        puname =  intent.getStringExtra("puname");
        puphone =  intent.getStringExtra("puphone");
        appuser_id =  intent.getStringExtra("paid");
        token =  intent.getStringExtra("token");
        et_upt= (TextView) findViewById(R.id.et_upt);
        et_upn= (TextView) findViewById(R.id.et_upn);
        et_usd= (EditText) findViewById(R.id.et_usd);
        et_ued= (EditText) findViewById(R.id.et_ued);
        et_upt.setText(puphone);
        et_upn.setText(puname);
        new Thread(){
            public void run(){
                final String result= SelepoService.SelepoByClientPost(bid,appuser_id,token);
                System.out.println(bid);
                System.out.println(appuser_id);
                if (result!=null){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {

                            try {
                                //JSON字符串
                                //根据JSON字符串 获得JSON object对象
                                JSONObject jsonObject = new JSONObject(result);
                                //根据key 获取相应的value
                                JSONObject data=jsonObject.getJSONObject("data");
                                starttime = data.getString("see_starttime");
                                endtime = data.getString("see_endtime");
                                System.out.println("开始时间"+starttime);
                                System.out.println("结束时间"+endtime);
                                et_usd.setText(starttime);
                                et_ued.setText(endtime);
                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }

                    });
                }
                else{
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(UpdatepersonActivity.this,"结果"+result,Toast.LENGTH_LONG).show();
                        }
                    });
                }
            };

        }.start();


    }
    public void Upnext(View view){
        final String starttime=et_usd.getText().toString().trim();
        final String endtime=et_ued.getText().toString().trim();

            new Thread() {
                public void run() {
                    final String result = UpnextService.UpnextByClientPost(puid,starttime,endtime, token);
                    if (result != null) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {

                                Toast.makeText(UpdatepersonActivity.this, result, Toast.LENGTH_LONG).show();
                            }
                        });
                    } else {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(UpdatepersonActivity.this, "日期时间格式错误", Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                }

                ;

            }.start();
        finish();
    }
    public void Caidan1(View view){
        Intent intent=new Intent(this,MainActivity.class);
        intent.putExtra("flag",1);
        startActivity(intent);
    }
    public void Caidan2(View view){
        Intent intent=new Intent(this,MainActivity.class);
        intent.putExtra("flag",2);
        startActivity(intent);
    }
    public void Caidan3(View view){
        Intent intent=new Intent(this,MainActivity.class);
        intent.putExtra("flag",3);
        startActivity(intent);
    }
    public void Caidan5(View view){
        Intent intent=new Intent(this,MainActivity.class);
        intent.putExtra("flag",4);
        startActivity(intent);
    }
    public void Finish(View view){
        finish();
    }
    @Override
    public void onClick(View view) {

    }

}
